package vy.org.app.page.lookup.profession;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.lookup.VyLookupProfessionDAO;
import org.vy.dal.dao.lookup.VyLookupProfessionDO;

import vy.org.app.common.AppConstants;
import vy.org.app.common.BaseAction;
import vy.org.app.common.ModeEnum;
import vy.org.app.common.ModuleEnum;

/**
 * @author Ravi Shankar
 * 
 */
public class MntnProfessionAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {
		MntnProfessionForm form = (MntnProfessionForm) actionForm;
		VyLookupProfessionDO dto = new VyLookupProfessionDO();

		if (form != null && form.getMode() != null) {
			if (ModeEnum.ADD.getName().equals(form.getMode())) {
				dto = MntnProfessionAssembler.getAssembler()
						.getLookupProfessionDO(form);

				try {
					VyLookupProfessionDAO.insert(dto);
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (ModeEnum.DELETE.getName().equals(form.getMode())) {
				dto = MntnProfessionAssembler.getAssembler()
						.getLookupProfessionDO(form);
				try {
					VyLookupProfessionDAO.delete(dto.getProfessionCode());
				} catch (Exception e) {
					e.printStackTrace();
				}

			} else if (ModeEnum.SEARCH.getName().equals(form.getMode())) {
				dto = MntnProfessionAssembler.getAssembler()
						.getLookupProfessionDO(form);
				try {

					request.setAttribute(AppConstants.RESULT,
							VyLookupProfessionDAO.findByParam(dto));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {

		return ModuleEnum.MAINTAIN_PROFESSION;
	}

}
